<?php
namespace app\index\controller;
use app\index\model\Ticket as Tickets;

class Ticket extends Comm
{
	public function index()
	{
		$ticket = new Tickets();
		$rs = $ticket->index();
		$this->assign('rs', $rs);
		return view('index');
	}
	public function add()
	{
		if(isset($_POST['submit']))
		{
			$data = $_POST;
			$ticket = new Tickets();
			$info = $ticket->add($data);
			if($info==1)
			{
				$this->success('添加成功','index');
			}else
			{
				$this->error('添加失败','index');
			}
		}
		$shang=db('issue')->select();
		return view('add',['shang' => $shang]);
	}
	public function del()
	{
		$id=input('id');
        $result = ticket::destroy($id);
        if($result)
        {   
            $this->success('删除成功','index');
        }else
        {
            $this->error('删除失败','index');
        }
	}
	public function edit()
	{
		if(isset($_POST['submit'])){
			// echo '<pre>';var_dump($_POST);die;
	       	$id = input('hid');
	        $money = input('money');
	        $min = input('min');
	        $stoptime = input('stoptime');
	        $intergral = input('intergral');
	        $comment = input('comment');
	        $issueid = input('issueid');
	        $number = input('number');
	        $Ticket = new Tickets();
	        $rs = $Ticket->uedit($id,$money,$min,$stoptime,$intergral,$comment,$issueid,$number);
	        if($rs){
	            $this->success('修改成功','index');
	        }else{
	            $this->error('修改失败','index');
        	}
        }else{
        	//获取修改信息
	        $id = input('id');
	        $ticket = new Tickets();
	       	$result = $ticket->edits($id);
	       	$shang=db('issue')->select();
	       	$sstoptime = db('ticket')->where('id',$id)->field('stoptime')->find();
	       	$time = $sstoptime['stoptime'];
			$times = explode(" ", $time);
			$stoptimes = $times[0];
			$stoptimess = $times[1];
			$stoptime = $stoptimes.'T'.$stoptimess;
			$this->assign('shang',$shang);
	        return view('edit',['result'=>$result,'time'=>$stoptime]);
    	}
	}
}